﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Sector7.Restaurant.CoreType.Enums;
using Sector7.Restaurant.Modules.REST.Utility;
using Sector7.Restaurant.Modules.REST.LocalService;
using Sector7.Restaurant.Biz;
using Sector7.Framework.Utility;
using Sector7.Framework.Core;
using Sector7.Framework.Enums;

namespace Sector7.Restaurant.Modules.REST.Windows
{
    /// <summary>
    /// AddEmployeeGroupWindow.xaml 的交互逻辑
    /// </summary>
    public partial class AddEmployeeGroupWindow : AddModeWindowBase
    {
        public AddEmployeeGroupWindow()
        {
            InitializeComponent();
        }

        public RS_EmployeeGroup EmployeeGroup
        {
            get { return m_entity as RS_EmployeeGroup; }
            set { m_entity = value; }
        }

        protected override void InitializeForCreating()
        {
            EmployeeGroup = new RS_EmployeeGroup();
            EmployeeGroup.Employees = new List<RS_Employee>();
        }

        protected override void InitializeForUpdating()
        {
            btnContinue.Visibility = Visibility.Hidden;
        }

        protected override void AddData()
        {
            EmployeeGroup.Permission = 999;

            switch (m_crud)
            {
                case CrudType.Create:
                    EmployeeGroup.GroupId = Aide.LocalClient.Invoke<int>(
                        service => service.AddEmployeeGroup(EmployeeGroup));
                    break;
                case CrudType.Update:
                    EntityDelta delta = ClientUtil.CreateDelta<EntityDelta>(typeof(RS_EmployeeGroup));
                    delta.Conditions.Add("GroupId", EmployeeGroup.GroupId);
                    delta.DeltaProperties.Add("GroupName", EmployeeGroup.GroupName);
                    delta.DeltaProperties.Add("BonusRate", EmployeeGroup.BonusRate);
                    delta.DeltaProperties.Add("Permission", EmployeeGroup.Permission);

                    Aide.LocalClient.Invoke<int>(
                        service => service.SetEmployeeGroup(delta));
                    break;
                default:
                    break;
            }

            base.AddData();
        }
    }
}
